home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 9 / develop 9 code / Tracks / cdev.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  9.5 KB  |  302 lines  |  [TEXT/MPS ]

  1. /****  TRACE CDEV COPYRIGHT 1990, 1991 ORION NETWORK SYSTEMS ALL RIGHTS RESERVED ****/
  2. #ifndef    __CDEV__
  3. #define    __CDEV__
  4.  
  5. #include "tracemodule.h"
  6.  
  7. #include    <Dialogs.h>
  8. #include    <Controls.h>
  9. #include    <Types.h>
  10. #include     <QuickDraw.h>
  11.  
  12. /*********************************************************************/
  13. /************************         DEFINES             ************************/
  14. /*********************************************************************/
  15.  
  16. #define    kFieldsPerBank        4        /* How many mask names per bank */
  17. //    This is how many names fit in the cdev's scroll window.
  18. #define    kBitsPerMask        128
  19.  
  20.  
  21. #define kOurKey 0x91726358        
  22. #define    kDefaultFileName "\pTracks Prefs"
  23. #define    kTraceMaskID    0
  24. #define    kBreakMaskID    1
  25.  
  26. #define    kMaxNumSizes    15        // Array size of buffer sizes...
  27.  
  28. #define kCDEVCreator    'BNNY'
  29.  
  30.  
  31. /*****  DITL items             *****/
  32. enum
  33. {
  34.     iTitleStr = 1,
  35.     iOnChk,iOffChk,
  36.     iOnMsg,iOffMsg,
  37.     iErrorStr,iErrorNumberStatic,iErrorMsgStatic,
  38.     iAutoWriteChk,iAutoWriteMsg,
  39.     iConfigFileButton,iFileNameStatic,
  40.     iFileSizeStr,iFileSizeStatic,iResetEOFButton,
  41.     iBufferSizeStr,iBufferSizeStatic,iSizeIncrement,iSizeDecrement,
  42.     iClearBufferButton,
  43.     iBytesBufferedStr,iBytesBuffedStatic,
  44.     iWriteBufferButton,
  45.     iLevel1Button,iBkptEllipsisButton,iMaskNumStatic,
  46.     iMaskEllipsisButton,
  47.     iChecks_Start = 28,
  48.     iDebugChecks_Start = 32,
  49.     iNames_Start = 36,
  50.     iScrollBarUserItem = 40,
  51.     iLevel2Button,iLevel3Button,iLevel4Button
  52. };
  53.  
  54. #define    kBugPictureID    -4062
  55. enum    {kTraceMask,kBreakMask};    /* For getting and setting mask, (whichmask) */
  56. enum
  57. {
  58.     kNoErrMsg=1,
  59.     kDriverError,
  60.     kBufferNotClear,
  61.     kInitializationFail,
  62.     kFileError,
  63.     kUnimplementedError,
  64.     kMemoryError,
  65.     kVersionError
  66. };
  67.  
  68. #define    kNumberOfErrors    5        /* The number of messages in STR# resource */
  69.  
  70. /***** Self definable        *****/
  71.  
  72. #define    kNumberOfBanks        (kBitsPerMask / kFieldsPerBank)                /* 16 with 8 fields each.. */
  73. #define    iChecks_End            iChecks_Start + kFieldsPerBank-1
  74. #define    iNames_End            iNames_Start + kFieldsPerBank -1
  75. #define    iDebugChecks_End    iDebugChecks_Start + kFieldsPerBank -1
  76. #define    kMaxBankSize        kNumberOfBanks-1                        /* 0..7 array of shex's */
  77. #define    kMinBankSize        0
  78.  
  79. #define    kTraceErrorsID        -4063        /* STR# list for error conditions */
  80.             
  81. #define kInternalMsg        -1        /* Used to report message to user via ReportResult */
  82. #define    kSizeIndexDefault    1        /* BufferSize[kSizeIndexDefault] = startup default size */
  83.  
  84.  
  85. #define kExternalNamesListID    777    // STR# list in target app..
  86.  
  87. #define kDotDrvrNameType    'kDRp'    // holds ".ANSA" (pascal string)
  88. #define kDotDrvrNameID        128
  89.  
  90. #define kDriverNameResType    'kDRp'    // Holds target app's name
  91. #define kDriverNameResID    129        // eg "SNAps Access"  (pascal string)
  92.  
  93.  
  94. /********************************************************************/
  95. /************************ THE T_CDEV CLASS **************************/
  96. /********************************************************************/
  97.  
  98. class  t_cdev {
  99. public:
  100.  
  101.         /*  instance variables  */
  102.         
  103.         /** Dispatch Globals */
  104. WindowPeek                fDp;                /*  the Control Panel  */
  105. short                    fWindRefnum;        /*  refnum of Control Panel DA  */
  106. short                    fRsrcID;            /*  base resource ID  */
  107. short                    fLastItem;            /*  # of last Control Panel item  */
  108. EventRecord                *fEvent;            /*  ==> last event  */
  109. long                    fStatus;            /*  value to be returned  */
  110.         /* Driver Stuff */
  111. long                    fKey;
  112. short                     fTraceRefNum;
  113.  
  114. ControlHandle            fScrollBar;        /* The scroll bar. Not a regular DITL for various reasons */
  115. Rect                    fSBarRect;        /* Holds Rectangle area of scroll bar */
  116.  
  117. MaskType                fTraceMask; /* This the cdev's copy of the 128 bits of mask data */
  118. MaskType                fBreakMask;    /* 0-127 bit mask for breaking into debugger.  */
  119.  
  120. Boolean                    fBreakOnceThenClear;    // If this is true, breakpoints
  121.                                 // clear themselves after being called--
  122.                                 // This is the default, so that the user
  123.                                 // can be sure that it won't get called 
  124.                                 // so often and repeatedly, that he won't 
  125.                                 // have time to turn off the break points
  126.                                 // with the cdev.
  127. Boolean                    fTraceOnStartup;    // This will allow the user
  128.                                 // to have the driver install and begin
  129.                                 // tracing from startup (reboot).  
  130.                                 // Not currently implemented.
  131. short                    fMaskIndex;        /* Keeps track of which bank of mask names is shown */
  132. Boolean                    fAutoWriteOn;    /* Periodic write to file on/off */
  133. Boolean                    fTraceEnabled;    /* Trace on or off */
  134.  
  135. lhex                    fBytesWritten;    /* Size of Output file */
  136. lhex                    fBytesBuffered;    /* Bytes in buffer */
  137.  
  138. shex                    fCurrentSizeIndex;        /* which of buffer size is current */
  139. lhex                    fBufferSize; /* Actual Buffer Size */
  140. shex                    fBufferNumSizes;//    # pos. sizes. defined in init.cp
  141. lhex                    fBufSizesHandle[kMaxNumSizes];    // array of sizes.. (0-1M)
  142. TraceStatusBlk             fTraceStatus;        /* Holds most current trace status record... */
  143.  
  144. PicHandle                fBugPicture;    /* Shows that a breakpoint has been set.. */
  145.  
  146. Handle                    fFieldNames;        // Handle to copy of Str# resource
  147. Handle                    fDriverDotName;        // Such as "\p.ASNA" 
  148. Handle                    fTargetAppName;        // Such as "\pSNAps Access"
  149.  
  150. // long    fTargFileDirID;    // directoryID for the target driver's file
  151. // long    fPrefFileDirID;    // directoryID for the target driver's file
  152. long    unused1;
  153. long     unused2;
  154.  
  155. Boolean                    fInCDEVMode;    // as opposed to inExtended...
  156.  
  157. // These are semi-constants, in that they only change when the dialog
  158. //    switches from the cdev to the extended dialog... and vice versa.
  159. // (To switch to the extended mode, hit the Extended Dialog… button in the cdev.
  160. //    
  161. short    fMinBankSize,fMaxBankSize,fFieldsPerBank;
  162. short    fChecks_Start,fChecks_End,fNames_Start,fNames_End;
  163. short    fDebugChecks_Start, fDebugChecks_End;
  164. short    fMaskNumStatic,fErrorMsgStatic,fErrorNumberStatic;
  165.  
  166. Str31    fDefaultFileName;
  167. SysEnvRec    fEnvironment;
  168.  
  169.  
  170. /*  METHODS  */
  171.  
  172. /*****    Methods that call the trace driver                 */
  173.  
  174. public:
  175. long            Message(short, short);    /*  dispatch message          */
  176. void            Error(long);                /*  set error return          */
  177. void            ChangeBank(short    NewBankNumber);
  178.  
  179. private:
  180. snum            TraceInit();        /* Called once at startup...  If failed, returns false     */
  181. OSErr            EnableTrace(Boolean    On);
  182. OSErr            EnableBuffer(Boolean    On);
  183. OSErr            EnableFile(char *fName,short vRefNum);        /* Called to set the file name */
  184. OSErr            ToggleAutoWrite();
  185. OSErr            DriverToCdevMask(short    csCode);    // Gets Driver's copy of mask
  186. OSErr            CdevMaskToDriver(short    csCode);    // Sends Cdev's copy of mask to driver
  187. void            ResetEOF();                /* Sets EOF of current output file to Zero */
  188. void             WriteBufferNow();
  189. void             ClearBufferNow();
  190. void            ReportResult(short    result,short    MsgNum);    /* Simply puts result code in dialog, */
  191. OSErr            UpdateTraceStatusBlk(void);
  192. void            BreakPointHelp(void);
  193. void             GetFieldName(char *itemName, short index);
  194.  
  195.  
  196. short            GetFolderVol(OSType type);
  197.  
  198.  
  199. // Prefrence stuff
  200. void            DoLoad();
  201. Boolean            LoadFieldNames();
  202. void            GetTargAppStuff();    // gets Str# list & fDriverDotName
  203.  
  204.  
  205. /*        Standard CDEV calls that are overridden    */
  206.  
  207. OSErr            Init(void);            /*  "initDev"      */
  208. void            Update(void);        /*  "updateDev"      */
  209. void            Activate(void);        /*  "activDev"      */
  210. void            Deactivate(void);    /*  "deactiveDev" */
  211. void            ItemHit(short);        /*  "hitDev"          */
  212. void            Key(short);            /*  "keyEvtDev"      */
  213. void            Close();            /*  "CloseDev"        */
  214. void            Idle(void);            /*  "nulDev"          */
  215.  
  216. /*     DITL manipulation methods         */
  217.  
  218. void            DGetString(short    item,Str255            str);
  219. void            DSetString(short    item,Str255            str);
  220. void            DSetLong(short    item,long    value);
  221. void            DSetControl(short theitem,short value);
  222. void            DEnableControl(ControlHandle Control,Boolean Enable);
  223. void            DEnableItem(short item,Boolean Enable);
  224. void            GetDItemFrame(short    item,Rect    *r);
  225. Boolean            TrackItem(int    item);        /* Tracks Mouse in Pict D. Item */
  226. void            DHidePictItem(short theitme,Boolean Enable);
  227. void            DrawABug(short    theitem,Boolean    Draw);    /*Draws or Erases Debugger() bug symbol */
  228.  
  229. /* Scroll bar routines */
  230. void            HandleScrollBar(void);
  231.  
  232. /* Checks and scroll field.... */
  233. void            CheckMarkHit(short);
  234. void            DebugMarkHit(short);
  235. void            UpdateFields();    
  236. /**********************    Alternate DLOG Screen ****************/
  237. void ExtendedClose(Ptr saveGlobs);
  238. Boolean ExtendedSetup(Ptr saveGlobs);
  239. void DoExtendedView();
  240.  
  241.  
  242. void DoCopyMask(MaskType src, MaskType dst);
  243.  
  244. /*****    BUTTON ACTIONS     *****/
  245.  
  246. void            SetOnOff(Boolean    On);
  247. void            SetSize(short    whichhit);
  248. void            FillMask(short WhichMask, Boolean SetCondition);
  249. void            SetName();
  250. void            DoSave(Boolean JustErasePrefs);
  251.  
  252.  
  253. /* Menu Stuff (ignored) */
  254. void            CmdKey(short);                /*  "keyEvtDev" (command)  */
  255.  
  256.  
  257. };
  258.  
  259. pascal    void    ScrollFilter(ControlHandle    SBar,short    partCode);    /* for scroll bar */
  260.  
  261. // *************************************************************************************** //
  262. //            Extended Dialog Stuff for CDEV. 
  263.             
  264. // Dialog Item List ID's
  265. enum {keOkayButton = 1,keCancelButton,keNamesStart,keNamesEnd = 18,
  266.         keDebugAreaStart,keDebugAreaEnd=34,keChecksStart,keChecksEnd = 50,
  267.         keScrollBarArea,
  268.         keClearAll,keSetAll,keClearBreakPts,keClearOnceCheckBox,keSave,keLoad,keAutoWrite,
  269.         keChangesInfo,keMaskNumStatic,keTraceOnStartup,keErrorNumberStatic,keErrorMsgStatic,keRevertPrefs};
  270.         
  271.  
  272. // There will be eight screens (banks) of mask names (0-7) in the scrollable field.
  273. //    of the larger scroll area.  This is in the recommended system font
  274. //    size. 
  275.  
  276. #define    kExtendedDialogID    -4062
  277. #define    keMinBankSize    0
  278. #define    keMaxBankSize    7
  279. #define    keFieldsPerBank 16
  280.  
  281. typedef    struct
  282.     {
  283.         ControlHandle    ScrollBarControl;
  284.         short             MaskIndex;
  285.         Boolean            TraceStartup;        // Ability to trace from init startup
  286.         Boolean            InitialTraceState;
  287.         Boolean            BOTCCopy;
  288.         Boolean            AutoWriteOn;
  289.         WindowPeek        DP;
  290.         short            LastItem;
  291.         lhex            BreakMaskCopy[4];
  292.         lhex            TraceMaskCopy[4];
  293.     } SavedGlobals, *SavedGlobalsPtr;
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. #endif
  302.